/*
@Time : 2021/2/5 14:09
@Author : 吴周海
@Mail: wzh200x@126.com
@File : messageData.go
@Software: GoLand
*/
package game

import (
	"math/rand"
	"net/url"
	"strconv"
	"time"
)

type GameApiMessage struct {
	Api         string //	API接口名称
	Sid         string //  服务器ID
	MessageKey  string //  消息KEY,不是加密的那个KEY,目前看来,服务器那边没啥用
	MessageData string //  消息内容
	Tm          int64  //  毫秒级时间戳
	Sign        string //  消息签名
}

func (g *GameApiMessage) FormatReUrl() string {
	u := url.Values{}
	u.Set("a", g.Api)
	u.Set("s", g.Sid)
	u.Set("k", g.MessageKey)
	u.Set("d", g.MessageData)
	u.Set("tm", strconv.FormatInt(g.Tm, 10))
	u.Set("sign", g.Sign)
	//u := "a=" + g.Api + "&s=" + g.Sid + "&k=" + g.MessageKey + "&d=" + g.MessageData + "&tm=" +
	//	strconv.FormatInt(g.Tm, 10) + "&sign=" + g.Sign
	return u.Encode()
}
func NewGameApiMessage(a string, s string, k string, d string) *GameApiMessage {
	newMessage := &GameApiMessage{
		Api:         a,
		Sid:         s,
		MessageKey:  k,
		MessageData: d,
		Tm:          0,
		Sign:        "",
	}
	newMessage.Tm = time.Now().Unix()*1000 + int64(rand.Intn(888)) + 111
	return newMessage
}
